import java.util.Iterator;
import java.util.LinkedList;

public class MyHashSet {
    private static  final int base = 769;
    private LinkedList[] list;

    public MyHashSet() {
        list = new LinkedList[base];
        for (int i = 0; i < base; i++) {
            list[i] = new LinkedList<Integer>();
        }
    }

    public void add(int key) {
        int h = hash(key);
        Iterator<Integer> iterator = list[h].iterator();
        while (iterator.hasNext()){
            Integer elem = iterator.next();
            if (elem == key){
                return;
            }
        }
        list[h].offerLast(key);
    }

    public void remove(int key) {
        int h = hash(key);
        Iterator<Integer> iterator = list[h].iterator();
        while (iterator.hasNext()) {
            Integer elem = iterator.next();
            if (elem == key){
                list[h].remove(elem);
                return;
            }
        }
    }

    public boolean contains(int key) {
        int h = hash(key);
        Iterator<Integer> iterator = list[h].iterator();
        while (iterator.hasNext()) {
            Integer elem = iterator.next();
            if (elem == key){
                return true;
            }
        }
        return false;
    }

    public static int hash(int key){
        return key % base;
    }
}
